<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <include file="./Public/Admin/header.html" />
</head>
<body>
<div id="main">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="box">
                    <div class="box-title">
                        <div class="span4">
                            <h3><i class="icon-table"></i>系统菜单管理</h3>
                        </div>
                    </div>
                    <div class="box-content">
                        <div class="row-fluid">
                            <div class="span12 control-group">
                                <div class="span4">
                                    <a class="btn" href="{:U('Admin/Permission/addmenus')}?action=add"><i class="icon-plus"></i>添加系统菜单</a>

                                    <a class="btn" href="javascript:location.reload()"><i class="icon-refresh"></i>刷新</a>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid dataTables_wrapper">
                            <table id="listTable" class="table table-bordered table-hover  dataTable">
                                <thead>
                                <tr>
                                    <th>菜单名称</th>
                                    <th>排序号</th>
                                    <th>链接</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach($menus as $item):?>
                                <tr>
                                    <td style="text-align:left;">
                                        <?php echo $item['sys_menu_name'];?>
                                    </td>
                                    <td><?php echo $item['sort_num'];?></td>
                                    <td><?php echo $item['link_url'];?></td>
                                    <td class='hidden-480'>
                                        <a href="{:U('Admin/Permission/addmenus')}?action=edit&sys_menu_id=<?php echo $item['sys_menu_id'];?>" class="btn" rel="tooltip" title="编辑"><i class="icon-edit"></i>编辑</a>
                                        <a href="javascript:void(0);" class="btn" rel="tooltip" title="删除" attr="deltext_<?php echo $item['sys_menu_id'];?>"><i class="icon-remove"></i>删除</a>
                                    </td>
                                </tr>
                                <?php
                                                $ejmenus=M('sys_menu')->where(array('parent_id'=>$item['sys_menu_id']))->order('sort_num asc')->select();
                                if(count($ejmenus)>0):foreach($ejmenus as $child):
                                ?>
                                <tr>
                                    <td style="text-align:left;padding-left:24px;">
                                        <img src="__PUBLIC__img/t.gif"/>
                                        <?php echo $child['sys_menu_name'];?>
                                    </td>
                                    <td><?php echo $child['sort_num'];?></td>
                                    <td><?php echo $child['link_url'];?></td>
                                    <td class='hidden-480'>
                                        <a href="{:U('Admin/Permission/addmenus')}?action=edit&sys_menu_id=<?php echo $child['sys_menu_id'];?>" class="btn" rel="tooltip" title="编辑"><i class="icon-edit"></i>编辑</a>
                                        <a href="javascript:void(0);" class="btn" rel="tooltip" title="删除" attr="deltext_<?php echo $child['sys_menu_id'];?>"><i class="icon-remove"></i>删除</a>
                                    </td>
                                </tr>
                                <?php
                                                $sjmenus=M('sys_menu')->where(array('parent_id'=>$child['sys_menu_id']))->order('sort_num asc')->select();;
                                if(count($sjmenus)>0):foreach($sjmenus as $sj):
                                ?>
                                <tr>
                                    <td style="text-align:left;padding-left:48px;">
                                        <img src="__PUBLIC__img/t.gif"/>
                                        <?php echo $sj['sys_menu_name'];?>
                                    </td>
                                    <td><?php echo $sj['sort_num'];?></td>
                                    <td><?php echo $sj['link_url'];?></td>
                                    <td class='hidden-480'>
                                        <a href="{:U('Admin/Permission/addmenus')}?action=edit&sys_menu_id=<?php echo $sj['sys_menu_id'];?>" class="btn" rel="tooltip" title="编辑"><i class="icon-edit"></i>编辑</a>
                                        <a href="javascript:void(0);" class="btn" rel="tooltip" title="删除" attr="deltext_<?php echo $sj['sys_menu_id'];?>"><i class="icon-remove"></i>删除</a>
                                    </td>
                                </tr>
                                <?php endforeach;endif;?>
                                <?php endforeach;endif;?>
                                <?php endforeach;?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        var delText = function(event){
            G.ui.tips.confirm_flag('您确定要删除吗?',function(){
                $.post("{:U('Admin/Permission/delmenu')}", {tid:event.data.tid},function(data){
                    if (data.errno ==0)
                    {
                        location.reload();
                    } else {
                        G.ui.tips.err(data.error);
                    }
                },'json');
            });
        };
        $("a[attr^='deltext_']").each(function(){
            var tmp = $(this).attr('attr').split('_');
            $(this).bind("click", {tid:tmp[1]}, delText);
        });
    });
</script>
</body>
</html>